/**
 * @filename:DirectoryInfoController 2025-04-27
 * @project starhub-schema  V1.0
 */
package com.starhub.api.directory.controller;

import cn.hutool.core.bean.BeanUtil;
import com.starhub.engine.directory.entity.DirectoryInfo;
import com.starhub.engine.directory.request.DirectoryInfoBsRequest;
import com.starhub.engine.directory.service.DirectoryInfoService;
import com.starhub.common.bean.ResultResp;
import com.starhub.common.security.util.SecurityUtils;
import com.starhub.common.sys.user.LoginUser;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;
/**   
 * <p>说明： 附件目录管理API接口层</P>
 * @version: V1.0
 * @author: 孙赛赛-sss
 * @time    2025-04-27
 *
 */
@Api(value="附件目录管理前台接口", tags = {"附件目录管理前台接口"},description = "编写者:孙赛赛-sss" )
@RestController
@RequestMapping("/api/starhub/directory")
public class DirectoryInfoController {
    @Autowired
    private DirectoryInfoService directoryService;
    /**
    * 日志
    */
    private static final Logger log = LoggerFactory.getLogger(DirectoryInfoController.class);

    /**
     * 附件目录管理新增
     */
    @ApiOperation(value = "附件目录管理新增", notes = "附件目录管理新增")
    @PostMapping("/addDirectoryInfo")
    public ResultResp<Map<String, Object>> addDirectoryInfo(@RequestBody DirectoryInfo directory){
        ResultResp resultResp = null;
        try {
            LoginUser user = SecurityUtils.getCurrentUser();
            resultResp = ResultResp.success(directoryService.addDirectoryInfo(user, directory).toString());
        }catch (Exception e){
            log.error(ExceptionUtils.getStackTrace(e));
            resultResp = ResultResp.fail("接口异常",e);
        }
        return resultResp;
    }

    /**
     * 附件目录管理修改
     */
    @ApiOperation(value = "附件目录管理修改", notes = "附件目录管理修改")
    @PostMapping("/updateDirectoryInfo")
    public ResultResp updateDirectoryInfo(@RequestBody DirectoryInfo DirectoryInfo){
        ResultResp resultResp = null;
        try {
            LoginUser user = SecurityUtils.getCurrentUser();
            resultResp = ResultResp.success(directoryService.updateDirectoryInfo(user, DirectoryInfo));
        }catch (Exception e){
            log.error(ExceptionUtils.getStackTrace(e));
            resultResp = ResultResp.fail("接口异常",e);
        }
        return resultResp;
    }

    /**
     * 附件目录管理信息获取
     */
    @ApiOperation(value = "附件目录管理信息获取", notes = "附件目录管理信息获取")
    @GetMapping("/getDirectoryInfoInfo/{id}")
    public ResultResp getDirectoryInfoInfo(@PathVariable Long id){
        ResultResp resultResp = null;
        try {
            LoginUser user = SecurityUtils.getCurrentUser();
            resultResp = ResultResp.success(directoryService.getDirectoryInfoInfo(user, id));
        }catch (Exception e){
            log.error(ExceptionUtils.getStackTrace(e));
            resultResp = ResultResp.fail("接口异常",e);
        }
        return resultResp;
    }

    /**
     * 附件目录管理物理删除
     */
    @ApiOperation(value = "附件目录管理物理删除", notes = "附件目录管理物理删除")
    @PostMapping("/deleteDirectoryInfoRecord")
    public ResultResp deleteDirectoryInfoRecord(@RequestBody DirectoryInfoBsRequest directoryInfoBsRequest){
        ResultResp resultResp = null;
        try {
            LoginUser user = SecurityUtils.getCurrentUser();
            directoryService.deleteDirectoryInfoRecord(user, directoryInfoBsRequest.getIds());
            resultResp = ResultResp.success("目录删除成功");
        }catch (Exception e){
            log.error(ExceptionUtils.getStackTrace(e));
            resultResp = ResultResp.fail("接口异常",e);
        }
        return resultResp;
    }

    /**
     * 附件目录管理列表获取
     */
    @ApiOperation(value = "附件目录管理树形列表获取", notes = "附件目录管理树形列表获取")
    @PostMapping("/getDirectoryInfoList")
    public ResultResp getDirectoryInfoList(@RequestBody DirectoryInfoBsRequest directoryInfoBsRequest){
        ResultResp resultResp = null;
        try {
            LoginUser user = SecurityUtils.getCurrentUser();
            Map<String , Object> params = BeanUtil.beanToMap(directoryInfoBsRequest);
            resultResp = ResultResp.success( directoryService.getDirectoryInfoList(user, params));
        }catch (Exception e){
            log.error(ExceptionUtils.getStackTrace(e));
            resultResp = ResultResp.fail("接口异常",e);
        }
        return resultResp;
    }

    @ApiOperation(value = "附件目录管理普通列表获取", notes = "附件目录管理普通列表获取")
    @PostMapping("/getDirectoryInfoNormalList")
    public ResultResp getDirectoryInfoNormalList(@RequestBody DirectoryInfoBsRequest directoryInfoBsRequest){
        ResultResp resultResp = null;
        try {
            LoginUser user = SecurityUtils.getCurrentUser();
            Map<String , Object> params = BeanUtil.beanToMap(directoryInfoBsRequest);
            resultResp = ResultResp.success( directoryService.getDirectoryInfoNormalList(user, params));
        }catch (Exception e){
            log.error(ExceptionUtils.getStackTrace(e));
            resultResp = ResultResp.fail("接口异常",e);
        }
        return resultResp;
    }


    @ApiOperation(value = "附件目录管理TreeSelect数据获取", notes = "附件目录管理TreeSelect数据获取")
    @PostMapping("/getDirectoryTreeSelect")
    public ResultResp getDirectoryTreeSelect(@RequestBody DirectoryInfoBsRequest directoryInfoBsRequest){
        ResultResp resultResp = null;
        try {
            LoginUser user = SecurityUtils.getCurrentUser();
            Map<String , Object> params = BeanUtil.beanToMap(directoryInfoBsRequest);
            resultResp = ResultResp.success( directoryService.getDirectoryTreeSeletList(user, params));
        }catch (Exception e){
            log.error(ExceptionUtils.getStackTrace(e));
            resultResp = ResultResp.fail("接口异常",e);
        }
        return resultResp;
    }


}